Skip to content

fix(api): cap per_page at 100 and fill open-ended date ranges#884

Merged
BYK merged 2 commits intomainfrom
fix/api-400-errors
Apr 30, 2026
Merged

fix(api): cap per_page at 100 and fill open-ended date ranges#884
BYK merged 2 commits intomainfrom
fix/api-400-errors

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 29, 2026

Summary

Fixes two bugs causing 400 Bad Request errors from the Sentry API, observed as a spike since 0.30.0 (CLI-F3, CLI-10):

  • per_page exceeds API limit: listTransactions and listSpans passed --limit directly as per_page. Values >100 were rejected by the API ("Invalid per_page value. Must be between 1 and 100."). Now caps at API_MAX_PER_PAGE (100) and auto-paginates when limit exceeds 100, matching the existing queryEvents pattern in discover.ts.

  • Open-ended date ranges produce incomplete params: timeRangeToApiParams() returned only start or only end for open-ended absolute ranges (e.g., --period ">=2024-01-01"). The API requires both boundaries. Now fills end=now for start-only ranges, start=end-90d for end-only ranges. Fixes all consumers (traces, spans, explore).

Fixes CLI-F3, CLI-10

Two bugs caused 400 Bad Request errors from the Sentry API:

1. listTransactions/listSpans passed --limit directly as per_page.
   Values >100 were rejected by the API. Now caps at API_MAX_PER_PAGE
   and auto-paginates when limit exceeds 100, matching the queryEvents
   pattern in discover.ts. (CLI-F3, CLI-10)

2. timeRangeToApiParams returned only start or only end for open-ended
   absolute ranges (e.g. --period '>=2024-01-01'). The API requires
   both. Now fills end=now for start-only, start=end-90d for end-only.
   Fixes all consumers (traces, spans, explore). (CLI-10)
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-884/

Built to branch gh-pages at 2026-04-30 17:12 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 29, 2026

Codecov Results 📊

6377 passed | Total: 6377 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +34
Passed Tests 📈 +34
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 84.78%. Project has 13168 uncovered lines.
❌ Project coverage is 75.89%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
src/lib/api/infrastructure.ts 67.74% ⚠️ 10 Missing
src/lib/api/traces.ts 96.15% ⚠️ 2 Missing
src/lib/time-range.ts 77.78% ⚠️ 2 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    76.03%    75.89%    -0.14%
==========================================
  Files          294       294         —
  Lines        54404     54606      +202
  Branches         0         0         —
==========================================
+ Hits         41362     41438       +76
- Misses       13042     13168      +126
- Partials         0         0         —

Generated by Codecov Action

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit df9a978. Configure here.

Comment thread src/lib/api/traces.ts Outdated
Extract the duplicated multi-page pagination loop from listTransactions,
listSpans, and queryEvents into a generic autoPaginate<T>() helper in
infrastructure.ts. This addresses Cursor Bugbot's feedback about code
duplication across the three call sites.

Also adds comprehensive tests for listTransactions and listSpans (26 tests
covering URL construction, per_page capping, auto-pagination, trimming,
sort, project handling, and cursor passthrough) to push patch coverage
above 80%.
@BYK BYK merged commit a4f72d4 into main Apr 30, 2026
26 checks passed
@BYK BYK deleted the fix/api-400-errors branch April 30, 2026 17:27
BYK added a commit that referenced this pull request Apr 30, 2026
…sages (CLI-1J8) (#893)

## Summary
- Widen `enrichDashboardError` to handle 400 on `create` (not just
`update`), so plan-limit messages like *"You may not exceed 10
dashboards on your current plan."* surface clearly instead of a raw
`ApiError: Failed to create dashboard: 400 Bad Request`
- Add test for 400 on create with plan-limit detail

Fixes CLI-1J8.

**Note:** CLI-1JD (explore 400 from open-ended time ranges) was already
fixed in #884.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant